home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / basic / boxdraw.bas < prev    next >
BASIC Source File  |  1992-10-24  |  8KB  |  226 lines

  1. '********************************BOXDRAW.BAS******************************
  2. '
  3. ' a program I HAD to make for my own use as I couldn't find one that I could
  4. ' understand.  A program to draw boxes on the screen in text mode using a
  5. ' SUB that you call with the box size, box line draw and box colors.
  6. ' Run it as a demo first and then add a box to one of your own programs.
  7. ' I have purposely put the variables on a line BEFORE the BOXDRAW1 SUB
  8. ' is called so that it is harder to mess up the CALL.
  9. '
  10. ' If you like this program, let me know.  If you make it better, give me
  11. ' a copy.  If you don't like it, tell me why.
  12. '
  13. '                      John De Palma on CompuServe 76076,571
  14. '                              October 23, 1992
  15. '**************************************************************************
  16. DEFINT A-Z
  17. DECLARE SUB boxdraw1 (top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
  18.  
  19. ' giving the color numbers names makes it easier to display and correct.   
  20.         CONST black = 0
  21.         CONST blue = 1
  22.         CONST green = 2
  23.         CONST cyan = 3
  24.         CONST red = 4
  25.         CONST magenta = 5
  26.         CONST brown = 6
  27.         CONST grey = 7            'don't use above 7 for background
  28.         CONST bright = 8
  29.         CONST white = 15          'added this
  30.         CONST blink = 16
  31.         CONST yellow = 14         'or use brown + bright
  32. DO                                'outside loop
  33. CLS
  34. top = 1: bottom = 25: left = 1: right = 80: lines = 1: forecolor = white: backcolor = blue
  35. CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
  36. LOCATE 1, 6: PRINT "Press a key to cycle the demo; PRESS <Esc> at the last screen to EXIT"
  37.     
  38.      DO UNTIL LEN(INKEY$)         'press a key to go on
  39.      LOOP
  40.      PLAY "p32"                   'a little multimedia
  41. top = 2: bottom = 10: left = 2: right = 30: lines = 0: forecolor = yellow: backcolor = brown
  42. CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
  43.      DO UNTIL LEN(INKEY$)
  44.      LOOP
  45.      PLAY "p32"
  46.  
  47. top = 9: bottom = 18: left = 15: right = 35: lines = 1: forecolor = blue: backcolor = grey
  48. CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
  49.      DO UNTIL LEN(INKEY$)
  50.      LOOP
  51.      PLAY "p32"
  52.  
  53. top = 10: bottom = 15: left = 40: right = 50: lines = 2: forecolor = red: backcolor = black
  54. CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
  55.      DO UNTIL LEN(INKEY$)
  56.      LOOP
  57.      PLAY "p32"
  58.  
  59. top = 2: bottom = 12: left = 50: right = 79: lines = 3: forecolor = white: backcolor = green
  60. CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
  61.      DO UNTIL LEN(INKEY$)
  62.      LOOP
  63.      PLAY "p32"
  64.  
  65. top = 12: bottom = 24: left = 2: right = 22: lines = 4: forecolor = yellow: backcolor = red
  66. CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
  67.      DO UNTIL LEN(INKEY$)
  68.      LOOP
  69.      PLAY "p32"
  70.  
  71. top = 6: bottom = 10: left = 30: right = 50: lines = 5: forecolor = bright + cyan: backcolor = cyan
  72. CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
  73.      DO UNTIL LEN(INKEY$)
  74.      LOOP
  75.      PLAY "p32"
  76.  
  77. 'it looks hard but it's really easy to draw a "shadowed box."
  78. 'all you have to do is first draw a box down and to the right (or left)
  79. 'of your display box using a black background and grey foreground.
  80. 'then call the display box.
  81. 'first the shadow....
  82.  
  83. top = 18: bottom = 24: left = 12: right = 74: lines = 0: forecolor = grey: backcolor = black
  84. CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
  85.  
  86.  
  87. 'then the display box...
  88.  
  89. top = 17: bottom = 23: left = 10: right = 70: lines = 2: forecolor = white: backcolor = cyan
  90. CALL boxdraw1(top%, bottom%, left%, right%, lines%, forecolor%, backcolor%)
  91.  
  92. LOCATE 18, 15: PRINT "This is the last screen.  Note this is a shadow box."
  93. LOCATE 19, 15: PRINT "I hope you find this program as much fun to use"
  94. LOCATE 20, 15: PRINT "as I had in developing it.  This program makes free"
  95. LOCATE 21, 15: PRINT "use of public code and stuff from other programs."
  96. LOCATE 23, 22: PRINT "John De Palma on CompuServe 76076,571"
  97.  
  98. 'If you really, really want to impress your friends then you may want
  99. 'to have a "see through" shadow.  You will have to redraw the
  100. 'portion of the box covered by the shadow and that is harder
  101. 'if you are layering boxes as you go.  The following code snippet will
  102. 'give you an idea on how to manually do this.
  103. LOCATE 24, 12: COLOR grey, black: PRINT STRING$(11, 223);
  104.  
  105.      DO UNTIL LEN(INKEY$)                    'must be some key strokes
  106.      IF INKEY$ = CHR$(27) THEN SYSTEM        'left in the buffer as
  107.      LOOP                                    'you need a double escape
  108.      PLAY "p32"                              'occasionally to get out
  109.                                              'of this program
  110.      WHILE INKEY$ = ""
  111.      IF INKEY$ = CHR$(27) THEN SYSTEM
  112.      WEND
  113.      PLAY "p32"
  114.  
  115. LOOP
  116. SYSTEM
  117.  
  118. DEFSNG A-Z
  119. SUB boxdraw1 (toprow%, bottomrow%, leftcolumn%, rightcolumn%, outline%, fgd%, bkgd%)
  120.  
  121. ' This routine draws and colors text boxes using color and line draw.
  122. ' If outline% is set to 5, prints thick horizontal bars, top & bottom rows.
  123. ' If outline% is set to 4, prints a bold-lined box
  124. ' If outline% is set to 3, prints a double sided box
  125. ' If outline% is set to 2, prints double top and single sided box.
  126. ' If outline% is set to 1, prints a single sided box.
  127. ' If outline% is set to 0, prints a box with no outline.
  128.       
  129. 'this sets the colors
  130.   COLOR fgd%, bkgd%
  131.  
  132.   middle% = rightcolumn% - leftcolumn%
  133.   lines% = toprow%
  134.   boxside$ = CHR$(186)                          'double line
  135.   boxside3$ = CHR$(179)                         'single line
  136.   boxside4$ = CHR$(219)                         'bold line
  137.  
  138.   boxtop% = (rightcolumn% - leftcolumn%) - 1
  139.  
  140.   boxtop$ = CHR$(201) + STRING$(boxtop%, 205) + CHR$(187)   'double line
  141.   boxtop2$ = CHR$(213) + STRING$(boxtop%, 205) + CHR$(184)  'double top, single side
  142.   boxtop3$ = CHR$(218) + STRING$(boxtop%, 196) + CHR$(191)  'single line
  143.   boxtop4$ = CHR$(220) + STRING$(boxtop%, 220) + CHR$(220)  'bold line
  144.  
  145.   boxbottom$ = CHR$(200) + STRING$(boxtop%, 205) + CHR$(188)  'double line
  146.   boxbottom2$ = CHR$(212) + STRING$(boxtop%, 205) + CHR$(190) 'double bottom, single side
  147.   boxbottom3$ = CHR$(192) + STRING$(boxtop%, 196) + CHR$(217) 'single line
  148.   boxbottom4$ = CHR$(223) + STRING$(boxtop%, 223) + CHR$(223) 'bold line
  149.  
  150.   midbox$ = STRING$(boxtop% + 1, 219)
  151.  
  152. 'this prints the box
  153.  
  154.   FOR boxsize% = toprow% TO bottomrow%
  155.     LOCATE lines%, leftcolumn%, 0
  156.     PRINT SPACE$(middle%);
  157.     lines% = lines% + 1
  158.   NEXT
  159.  
  160. 'this prints the box outline
  161.  
  162.   SELECT CASE outline%
  163.  
  164.   CASE 0
  165.   EXIT SUB
  166.  
  167.   CASE 1
  168.    
  169.     LOCATE toprow%, leftcolumn%
  170.     PRINT boxtop3$;
  171.     FOR outline% = toprow% + 1 TO bottomrow% - 1
  172.       LOCATE outline%, leftcolumn%
  173.       PRINT boxside3$;
  174.       LOCATE outline%, rightcolumn%
  175.       PRINT boxside3$;
  176.     NEXT outline%
  177.     LOCATE bottomrow%, leftcolumn%
  178.     PRINT boxbottom3$;
  179.  
  180.   CASE 2
  181.  
  182.     LOCATE toprow%, leftcolumn%
  183.     PRINT boxtop2$;
  184.     FOR outline% = toprow% + 1 TO bottomrow% - 1
  185.       LOCATE outline%, leftcolumn%
  186.       PRINT boxside3$;
  187.       LOCATE outline%, rightcolumn%
  188.       PRINT boxside3$;
  189.     NEXT outline%
  190.     LOCATE bottomrow%, leftcolumn%
  191.     PRINT boxbottom2$;
  192.  
  193.   CASE 3
  194.  
  195.     LOCATE toprow%, leftcolumn%
  196.     PRINT boxtop$;
  197.     FOR outline% = toprow% + 1 TO bottomrow% - 1
  198.       LOCATE outline%, leftcolumn%
  199.       PRINT boxside$;
  200.       LOCATE outline%, rightcolumn%
  201.       PRINT boxside$;
  202.     NEXT outline%
  203.     LOCATE bottomrow%, leftcolumn%
  204.     PRINT boxbottom$;
  205.  
  206.   CASE 4
  207.  
  208.     LOCATE toprow%, leftcolumn%
  209.     PRINT boxtop4$;
  210.     FOR outline% = toprow% + 1 TO bottomrow% - 1
  211.       LOCATE outline%, leftcolumn%
  212.       PRINT boxside4$;
  213.       LOCATE outline%, rightcolumn%
  214.       PRINT boxside4$;
  215.     NEXT outline%
  216.     LOCATE bottomrow%, leftcolumn%
  217.     PRINT boxbottom4$;
  218.  
  219. CASE 5
  220.     
  221.      LOCATE toprow%, leftcolumn%: PRINT midbox$;
  222.      LOCATE botto